use sea_orm_migration::prelude::*;

use entity::{resource, role_resource};

use crate::sea_orm::{ActiveModelTrait, NotSet};
use crate::sea_orm::ActiveValue::Set;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        let db = manager.get_connection();
        resource::ActiveModel {
            id: Set(43),
            parent_id: Set(1),
            resource_name: Set(Some("账号管理".to_string())),
            resource_code: Set(Some("accounts_manager".to_string())),
            resource_type: Set(Some(1)),
            resource_root: Set(Some(true)),
            resource_action: Set(Some(false)),
            order_number: Set(Some(0)),
            url: Set(Some("accountsManager".to_string())),
            api_path: NotSet,
            api_http_method: Default::default(),
            role: NotSet,
            status: Set(Some(true)),
            icon: NotSet,
            resource_desc: Set(Some("游戏账号管理菜单".to_string())),
        }
        .insert(db)
        .await?;
        resource::ActiveModel {
            id: Set(44),
            parent_id: Set(43),
            resource_name: Set(Some("账号详情".to_string())),
            resource_code: Set(Some("api_accounts_info".to_string())),
            resource_type: Set(Some(2)),
            resource_root: Set(Some(false)),
            resource_action: Set(Some(true)),
            order_number: Set(Some(0)),
            url: Default::default(),
            api_path: Set(Some("/api/accounts/info/".to_string())),
            api_http_method: Set(Some("GET".to_string())),
            role: NotSet,
            status: Set(Some(true)),
            icon: NotSet,
            resource_desc: Set(Some("游戏账号详情接口".to_string())),
        }
        .insert(db)
        .await?;
        resource::ActiveModel {
            id: Set(45),
            parent_id: Set(43),
            resource_name: Set(Some("账号列表".to_string())),
            resource_code: Set(Some("api_accounts_list".to_string())),
            resource_type: Set(Some(2)),
            resource_root: Set(Some(false)),
            resource_action: Set(Some(true)),
            order_number: Set(Some(0)),
            url: Default::default(),
            api_path: Set(Some("/api/accounts/list".to_string())),
            api_http_method: Set(Some("GET".to_string())),
            role: NotSet,
            status: Set(Some(true)),
            icon: NotSet,
            resource_desc: Set(Some("游戏账号列表接口".to_string())),
        }
        .insert(db)
        .await?;
        resource::ActiveModel {
            id: Set(46),
            parent_id: Set(43),
            resource_name: Set(Some("账号分页查询".to_string())),
            resource_code: Set(Some("api_accounts_page".to_string())),
            resource_type: Set(Some(2)),
            resource_root: Set(Some(false)),
            resource_action: Set(Some(true)),
            order_number: Set(Some(0)),
            url: Default::default(),
            api_path: Set(Some("/api/accounts/page".to_string())),
            api_http_method: Set(Some("POST".to_string())),
            role: NotSet,
            status: Set(Some(true)),
            icon: NotSet,
            resource_desc: Set(Some("游戏账号分页查询接口".to_string())),
        }
        .insert(db)
        .await?;
        resource::ActiveModel {
            id: Set(47),
            parent_id: Set(43),
            resource_name: Set(Some("添加账号".to_string())),
            resource_code: Set(Some("api_accounts_add".to_string())),
            resource_type: Set(Some(2)),
            resource_root: Set(Some(false)),
            resource_action: Set(Some(true)),
            order_number: Set(Some(0)),
            url: Default::default(),
            api_path: Set(Some("/api/accounts/add".to_string())),
            api_http_method: Set(Some("POST".to_string())),
            role: NotSet,
            status: Set(Some(true)),
            icon: NotSet,
            resource_desc: Set(Some("添加游戏账号接口".to_string())),
        }
        .insert(db)
        .await?;
        resource::ActiveModel {
            id: Set(48),
            parent_id: Set(43),
            resource_name: Set(Some("修改账号".to_string())),
            resource_code: Set(Some("api_accounts_update".to_string())),
            resource_type: Set(Some(2)),
            resource_root: Set(Some(false)),
            resource_action: Set(Some(true)),
            order_number: Set(Some(0)),
            url: Default::default(),
            api_path: Set(Some("/api/accounts/update".to_string())),
            api_http_method: Set(Some("POST".to_string())),
            role: NotSet,
            status: Set(Some(true)),
            icon: NotSet,
            resource_desc: Set(Some("修改游戏账号接口".to_string())),
        }
        .insert(db)
        .await?;
        resource::ActiveModel {
            id: Set(49),
            parent_id: Set(43),
            resource_name: Set(Some("删除账号".to_string())),
            resource_code: Set(Some("api_accounts_delete".to_string())),
            resource_type: Set(Some(2)),
            resource_root: Set(Some(false)),
            resource_action: Set(Some(true)),
            order_number: Set(Some(0)),
            url: Default::default(),
            api_path: Set(Some("/api/accounts/delete".to_string())),
            api_http_method: Set(Some("GET".to_string())),
            role: NotSet,
            status: Set(Some(true)),
            icon: NotSet,
            resource_desc: Set(Some("删除游戏账号接口".to_string())),
        }
        .insert(db)
        .await?;
        resource::ActiveModel {
            id: Set(50),
            parent_id: Set(43),
            resource_name: Set(Some("重置账号密码".to_string())),
            resource_code: Set(Some("api_accounts_reset_password".to_string())),
            resource_type: Set(Some(2)),
            resource_root: Set(Some(false)),
            resource_action: Set(Some(true)),
            order_number: Set(Some(0)),
            url: Default::default(),
            api_path: Set(Some("/api/accounts/reset_password".to_string())),
            api_http_method: Set(Some("GET".to_string())),
            role: NotSet,
            status: Set(Some(true)),
            icon: NotSet,
            resource_desc: Set(Some("重置游戏账号密码接口".to_string())),
        }
        .insert(db)
        .await?;
        resource::ActiveModel {
            id: Set(51),
            parent_id: Set(43),
            resource_name: Set(Some("充值点券".to_string())),
            resource_code: Set(Some("api_accounts_recharge_bonds".to_string())),
            resource_type: Set(Some(2)),
            resource_root: Set(Some(false)),
            resource_action: Set(Some(true)),
            order_number: Set(Some(0)),
            url: Default::default(),
            api_path: Set(Some("/api/accounts/recharge_bonds".to_string())),
            api_http_method: Set(Some("POST".to_string())),
            role: NotSet,
            status: Set(Some(true)),
            icon: NotSet,
            resource_desc: Set(Some("充值点券接口".to_string())),
        }
        .insert(db)
        .await?;
        resource::ActiveModel {
            id: Set(52),
            parent_id: Set(43),
            resource_name: Set(Some("重置角色创建限制".to_string())),
            resource_code: Set(Some("api_accounts_reset_create_role".to_string())),
            resource_type: Set(Some(2)),
            resource_root: Set(Some(false)),
            resource_action: Set(Some(true)),
            order_number: Set(Some(0)),
            url: Default::default(),
            api_path: Set(Some("/api/accounts/reset_create_role/".to_string())),
            api_http_method: Set(Some("GET".to_string())),
            role: NotSet,
            status: Set(Some(true)),
            icon: NotSet,
            resource_desc: Set(Some("重置角色创建限制接口".to_string())),
        }
        .insert(db)
        .await?;
        resource::ActiveModel {
            id: Set(53),
            parent_id: Set(43),
            resource_name: Set(Some("设置角色栏最大".to_string())),
            resource_code: Set(Some("api_accounts_set_max_role".to_string())),
            resource_type: Set(Some(2)),
            resource_root: Set(Some(false)),
            resource_action: Set(Some(true)),
            order_number: Set(Some(0)),
            url: Default::default(),
            api_path: Set(Some("/api/accounts/set_max_role/".to_string())),
            api_http_method: Set(Some("GET".to_string())),
            role: NotSet,
            status: Set(Some(true)),
            icon: NotSet,
            resource_desc: Set(Some("设置角色栏最大接口".to_string())),
        }
        .insert(db)
        .await?;
        resource::ActiveModel {
            id: Set(54),
            parent_id: Set(43),
            resource_name: Set(Some("开启全图王者".to_string())),
            resource_code: Set(Some("api_accounts_open_dungeon".to_string())),
            resource_type: Set(Some(2)),
            resource_root: Set(Some(false)),
            resource_action: Set(Some(true)),
            order_number: Set(Some(0)),
            url: Default::default(),
            api_path: Set(Some("/api/accounts/open_dungeon/".to_string())),
            api_http_method: Set(Some("GET".to_string())),
            role: NotSet,
            status: Set(Some(true)),
            icon: NotSet,
            resource_desc: Set(Some("开启全图王者接口".to_string())),
        }
        .insert(db)
        .await?;
        for id in 43..55 {
            role_resource::ActiveModel {
                id: NotSet,
                role_id: Set(1),
                resource_id: Set(id),
            }
            .insert(db)
            .await?;
        }
        Ok(())
    }

    async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
        Ok(())
    }
}
